package org.testtools.assertion;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;

public class XMLAssertion {

    static String schemaLang = "http://www.w3.org/2001/XMLSchema";

    static SchemaFactory factory = SchemaFactory.newInstance(schemaLang);

    public static boolean contentIsW3CValid(InputStream xsdFile, InputStream xmlFile) throws SAXException, IOException {

        // create schema by reading it from an XSD file:
        Schema schema = factory.newSchema(new StreamSource(xsdFile));
        Validator validator = schema.newValidator();

        // at last perform validation:
        validator.validate(new StreamSource(xmlFile));

        return true;
    }

}
